package com.santu.edu.supporter.biz.buildings.controller;

import com.santu.edu.supporter.biz.buildings.pojo.vo.BuildingsVO;
import com.santu.edu.supporter.biz.buildings.serice.BuildingsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author luoyaoqi
 * @createTime 2024/2/20
 * @description
 */
@RestController
@Validated
@RequiredArgsConstructor
@RequestMapping("buildings")
public class BuildingsController {

    private final BuildingsService buildingsService;


    @PostMapping("add")
    public Boolean addBuilding(@NotBlank(message = "楼栋名称不能为空") String buildName,
                               @NotNull(message = "typeCode不能为空") Integer typeCode,
                               @NotBlank(message = "schoolId不能为空") String schoolId) {
        return buildingsService.addBuilding(buildName, typeCode, schoolId);
    }

    @PostMapping("remove")
    public Boolean removeBuilding(@NotBlank(message = "buildingsId不能为空") String buildingsId) {
        return buildingsService.removeBuilding(buildingsId);
    }

    @GetMapping("get/by/typeCode")
    public List<BuildingsVO> getBuildingsList(@NotNull(message = "typeCode不能为空") Integer typeCode,
                                              @NotBlank(message = "schoolId不能为空") String schoolId) {
        return BuildingsVO.convert(buildingsService.getBuildingsList(typeCode, schoolId));
    }

}
